Use case: RNG generate NIST compliant random numbers in polling mode ¶
Sequence diagram ¶
Code snippet ¶
|
HAL1 |
HAL2 |
|---|---|
#define LENGTH 8
uint32_t aRandom32bit[LENGTH];
RNG_HandleTypeDef hrng;
RNG_ConfigTypeDef p_config;
hrng.Instance = RNG;
hrng.Init.ClockErrorDetection = RNG_CED_ENABLE;
p_config.Config1 = 0x01;
p_config.Config2 = 0x00;
p_config.Config3 = 0x02;
p_config.ClockDivider = RNG_CLKDIV_BY_32;
p_config.NistCompliance = RNG_NIST_COMPLIANT;
P_config.AutoReset = RNG_ARDIS_ENABLE;
p_config.HealthTest = 0x00009AAE;
p_config.NoiseSource = 0x000358D1;
HAL_RNG_Init(&hrng);
HAL_RNGEx_SetConfig(&hrng, &p_config);
for (int cnt=0; cnt < LENGTH - 1; cnt++)
{
if (HAL_RNG_GenerateRandomNumber(&hrng,
&aRandom32bit[cnt]) == HAL_ERROR)
{
HAL_RNGEx_RecoverSeedError(&hrng);
}
}
|
#define LENGTH 8
uint32_t aRandom32bit[LENGTH];
hal_rng_handle_t hrng;
HAL_RNG_Init(&hrng, HAL_RNG);
HAL_RNG_SetCertifiedNISTConfig(&hrng);
HAL_RNG_EnableClockErrorDetection(&hrng);
if (HAL_RNG_GenerateRandomNumber(&hrng,
aRandom32bit, LENGTH) == HAL_ERROR)
{
HAL_RNG_RecoverSeedError(&hrng);
}
|
Key changes ¶
In HAL2, random number generation APIs take a buffer and its size and fill it in one call.
Configuration and recovery APIs are updated (for example, HAL_RNG_SetCertifiedNISTConfig and HAL_RNG_RecoverSeedError).

